package com.gcsoftware.gateway.confLoader;

import java.util.Properties;

/**
 * Created by Qiusi on 18/4/11.
 */
public class LoadGWRbacParam
{
    private static LoadGWRbacParam ourInstance;

    public static LoadGWRbacParam getInstance()
    {
        if (null == ourInstance) {
            synchronized (LoadGWRbacParam.class) {
                if (null == ourInstance) {
                     ourInstance = new LoadGWRbacParam();
                }
            }
        }
        return ourInstance;
    }
    private static final String cfgName = "gw-rbac.properties";

    private static Properties prop;

    private LoadGWRbacParam()
    {
        prop = CfgLoader.cfgLoader(cfgName);
    }

    public int getIntValue(String key, int dftVal)
    {
        if ((null == prop.getProperty(key)))
        {
            return dftVal;
        }
        else
        {
            return Integer.parseInt(prop.getProperty(key));
        }
    }

    public String getStringValue(String key, String dftVal)
    {
        return (null == prop.getProperty(key)) ? dftVal :prop.getProperty(key);
    }

    public String getXmlSavePath() {
        return getStringValue("gateway.xml.path", CfgLoader.getFullPath() + "temp" + CfgLoader.fileSep);
    }
    public String getRedisHost() {
        return getStringValue("gateway.redis.host","127.0.0.1");
    }
    public int getRedisPort()
    {
        return getIntValue("gateway.redis.port", 6379);
    }
}
